{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def merge(filename):\n",
    "    testname = filename.replace('train', 'test')\n",
    "    train = pd.read_csv(filename)\n",
    "    test = pd.read_csv(testname)\n",
    "    data = pd.concat([train, test])\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\users\\demonsong\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\IPython\\core\\interactiveshell.py:2728: DtypeWarning: Columns (12,49) have mixed types. Specify dtype option on import or set low_memory=False.\n",
      "  interactivity=interactivity, compiler=compiler, result=result)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>Score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201e8bf2-77a2-3a98-9fcf-4ce03914e712</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>f4d51947-eac4-3005-9d3c-2f32d6068a2d</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>74aa7ae4-03a4-394c-bee0-5702d3a3082a</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>099661c2-4360-3c49-a2fe-8c783764f7db</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>97ca672d-e558-3542-ba7b-ee719bba1bab</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     Id  Score\n",
       "0  201e8bf2-77a2-3a98-9fcf-4ce03914e712      5\n",
       "1  f4d51947-eac4-3005-9d3c-2f32d6068a2d      4\n",
       "2  74aa7ae4-03a4-394c-bee0-5702d3a3082a      4\n",
       "3  099661c2-4360-3c49-a2fe-8c783764f7db      5\n",
       "4  97ca672d-e558-3542-ba7b-ee719bba1bab      5"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv('../input/data.csv')\n",
    "\n",
    "data_stacking = data[['Id', 'Score']].copy()\n",
    "data_stacking.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "lgbm_train_100.csv\n",
      "lgbm_train_101.csv\n",
      "lgbm_train_102.csv\n",
      "TextCNN_train.csv\n",
      "train_clf_0_label_lc_label_1.csv\n",
      "train_clf_0_label_lc_label_2.csv\n",
      "train_clf_0_label_lc_label_3.csv\n",
      "train_clf_0_label_lc_label_4.csv\n",
      "train_clf_0_label_lc_label_5.csv\n",
      "train_clf_1_label_lc_label_1.csv\n",
      "train_clf_1_label_lc_label_2.csv\n",
      "train_clf_1_label_lc_label_3.csv\n",
      "train_clf_1_label_lc_label_4.csv\n",
      "train_clf_1_label_lc_label_5.csv\n",
      "train_clf_2_label_lc_label_1.csv\n",
      "train_clf_2_label_lc_label_2.csv\n",
      "train_clf_2_label_lc_label_3.csv\n",
      "train_clf_2_label_lc_label_4.csv\n",
      "train_clf_2_label_lc_label_5.csv\n",
      "train_clf_3_label_lc_label_1.csv\n",
      "train_clf_3_label_lc_label_2.csv\n",
      "train_clf_3_label_lc_label_3.csv\n",
      "train_clf_3_label_lc_label_4.csv\n",
      "train_clf_3_label_lc_label_5.csv\n",
      "train_clf_5000_label_lc_label_1.csv\n",
      "train_lasso_1.csv\n",
      "train_lasso_2.csv\n",
      "train_lasso_3.csv\n",
      "train_lasso_4.csv\n",
      "train_lgbmc_lc_label_1.csv\n",
      "train_lgbmc_lc_label_2.csv\n",
      "train_lgbmc_lc_label_3.csv\n",
      "train_lgbmc_lc_label_4.csv\n",
      "train_lgbmc_lc_label_5.csv\n",
      "train_lgbmr_doc2vec_201.csv\n",
      "train_lgbmr_lr_0.csv\n",
      "train_lgbmr_lr_100.csv\n",
      "train_lgbmr_lr_101.csv\n",
      "train_lgbmr_lr_102.csv\n",
      "train_lgbmr_lr_200.csv\n",
      "train_lgbmr_lr_201.csv\n",
      "train_lgbmr_lr_202.csv\n",
      "train_lgbmr_lr_203.csv\n",
      "train_lgbmr_lr_204.csv\n",
      "train_lgbmr_lr_502.csv\n",
      "train_lgbmr_lr_504.csv\n",
      "train_lgbmr_lr_506.csv\n",
      "train_lgbmr_lr_507.csv\n",
      "train_lgbmr_lr_509.csv\n",
      "train_lgbmr_lr_510.csv\n",
      "train_lgbmr_lr_513.csv\n",
      "train_lgbmr_lr_517.csv\n",
      "train_lgbmr_lr_518.csv\n",
      "train_lgbmr_lr_519.csv\n",
      "train_lgbmr_lr_520.csv\n",
      "train_lgbmr_lr_521.csv\n",
      "train_lgbmr_lr_522.csv\n",
      "train_lgbmr_lr_523.csv\n",
      "train_lgbmr_lr_524.csv\n",
      "train_lgbmr_lr_525.csv\n",
      "train_lgbmr_lr_528.csv\n",
      "train_lgbmr_lr_530.csv\n",
      "train_lgbmr_lr_532.csv\n",
      "train_lgbmr_lr_534.csv\n",
      "train_lgbmr_lr_535.csv\n",
      "train_lgbmr_lr_536.csv\n",
      "train_lgbmr_lr_538.csv\n",
      "train_lgbmr_lr_540.csv\n",
      "train_lgbmr_lr_541.csv\n",
      "train_lgbmr_lr_543.csv\n",
      "train_lgbmr_lr_544.csv\n",
      "train_lgbmr_lr_547.csv\n",
      "train_lgbmr_lr_548.csv\n",
      "train_lgbmr_lr_550.csv\n",
      "train_lgbmr_lr_551.csv\n",
      "train_lgbmr_lr_552.csv\n",
      "train_lgbmr_lr_553.csv\n",
      "train_lgbmr_lr_554.csv\n",
      "train_lgbmr_lr_555.csv\n",
      "train_lgbmr_lr_559.csv\n",
      "train_lgbmr_lr_560.csv\n",
      "train_lgbmr_lr_561.csv\n",
      "train_lgbmr_lr_562.csv\n",
      "train_lgbmr_lr_563.csv\n",
      "train_lgbmr_lr_564.csv\n",
      "train_lgbmr_lr_565.csv\n",
      "train_lgbmr_lr_567.csv\n",
      "train_lgbmr_lr_568.csv\n",
      "train_lgbmr_lr_569.csv\n",
      "train_lgbmr_lr_570.csv\n",
      "train_lgbmr_lr_571.csv\n",
      "train_lgbmr_lr_572.csv\n",
      "train_lgbmr_lr_573.csv\n",
      "train_lgbmr_lr_574.csv\n",
      "train_lgbmr_lr_575.csv\n",
      "train_lgbmr_lr_578.csv\n",
      "train_lgbmr_lr_579.csv\n",
      "train_lgbmr_lr_580.csv\n",
      "train_lgbmr_lr_581.csv\n",
      "train_lgbmr_lr_582.csv\n",
      "train_lgbmr_lr_583.csv\n",
      "train_lgbmr_lr_584.csv\n",
      "train_lgbmr_lr_585.csv\n",
      "train_lgbmr_lr_586.csv\n",
      "train_lgbmr_lr_587.csv\n",
      "train_lgbmr_lr_588.csv\n",
      "train_lgbmr_lr_589.csv\n",
      "train_lgbmr_lr_592.csv\n",
      "train_lgbmr_lr_598.csv\n",
      "train_lgbmr_lr_599.csv\n",
      "train_lgbmr_lr_601.csv\n",
      "train_lgbmr_lr_602.csv\n",
      "train_lgbmr_lr_603.csv\n",
      "train_lgbmr_lr_605.csv\n",
      "train_lgbmr_lr_607.csv\n",
      "train_lgbmr_lr_609.csv\n",
      "train_lgbmr_lr_613.csv\n",
      "train_lgbmr_lr_615.csv\n",
      "train_lgbmr_lr_616.csv\n",
      "train_lgbmr_lr_619.csv\n",
      "train_lgbmr_lr_621.csv\n",
      "train_lgbmr_lr_622.csv\n",
      "train_lgbmr_lr_626.csv\n",
      "train_lgbmr_lr_627.csv\n",
      "train_lgbmr_lr_628.csv\n",
      "train_lgbmr_lr_629.csv\n",
      "train_lgbmr_lr_630.csv\n",
      "train_lgbmr_lr_631.csv\n",
      "train_lgbmr_lr_632.csv\n",
      "train_lgbmr_lr_634.csv\n",
      "train_lgbmr_lr_636.csv\n",
      "train_lgbmr_lr_637.csv\n",
      "train_lgbmr_lr_638.csv\n",
      "train_lgbmr_lr_640.csv\n",
      "train_lgbmr_lr_641.csv\n",
      "train_lgbmr_lr_642.csv\n",
      "train_lgbmr_lr_643.csv\n",
      "train_lgbmr_lr_644.csv\n",
      "train_lgbmr_lr_646.csv\n",
      "train_lgbmr_lr_647.csv\n",
      "train_lgbmr_lr_648.csv\n",
      "train_lgbmr_lr_650.csv\n",
      "train_lgbmr_lr_652.csv\n",
      "train_lgbmr_lr_653.csv\n",
      "train_lgbmr_lr_654.csv\n",
      "train_lgbmr_lr_655.csv\n",
      "train_lgbmr_lr_657.csv\n",
      "train_lgbmr_lr_658.csv\n",
      "train_lgbmr_lr_660.csv\n",
      "train_lgbmr_lr_664.csv\n",
      "train_lgbmr_lr_666.csv\n",
      "train_lgbmr_lr_670.csv\n",
      "train_lgbmr_lr_673.csv\n",
      "train_lgbmr_lr_674.csv\n",
      "train_lgbmr_lr_675.csv\n",
      "train_lgbmr_lr_676.csv\n",
      "train_lgbmr_lr_678.csv\n",
      "train_lgbmr_lr_679.csv\n",
      "train_lgbmr_lr_680.csv\n",
      "train_lgbmr_lr_682.csv\n",
      "train_lgbmr_lr_683.csv\n",
      "train_lgbmr_lr_684.csv\n",
      "train_lgbmr_lr_685.csv\n",
      "train_lgbmr_lr_686.csv\n",
      "train_lgbmr_lr_687.csv\n",
      "train_lgbmr_lr_688.csv\n",
      "train_lgbmr_lr_691.csv\n",
      "train_lgbmr_lr_692.csv\n",
      "train_lgbmr_lr_694.csv\n",
      "train_lgbmr_lr_695.csv\n",
      "train_lgbmr_lr_696.csv\n",
      "train_lgbmr_lr_697.csv\n",
      "train_lgbmr_lr_698.csv\n",
      "train_lgbmr_lr_699.csv\n",
      "train_lgbmr_lr_700.csv\n",
      "train_lgbmr_lr_701.csv\n",
      "train_lgbmr_lr_702.csv\n",
      "train_lgbmr_lr_704.csv\n",
      "train_lgbmr_lr_705.csv\n",
      "train_lgbmr_lr_706.csv\n",
      "train_lgbmr_lr_707.csv\n",
      "train_lgbmr_lr_708.csv\n",
      "train_lgbmr_lr_709.csv\n",
      "train_lgbmr_lr_710.csv\n",
      "train_lgbmr_lr_712.csv\n",
      "train_lgbmr_lr_714.csv\n",
      "train_lgbmr_lr_716.csv\n",
      "train_lgbmr_lr_717.csv\n",
      "train_lgbmr_lr_718.csv\n",
      "train_lgbmr_lr_719.csv\n",
      "train_lgbmr_lr_720.csv\n",
      "train_lgbmr_lr_721.csv\n",
      "train_lgbmr_lr_722.csv\n",
      "train_lgbmr_lr_723.csv\n",
      "train_lgbmr_lr_724.csv\n",
      "train_lgbmr_lr_726.csv\n",
      "train_lgbmr_lr_727.csv\n",
      "train_lgbmr_lr_729.csv\n",
      "train_lgbmr_lr_733.csv\n",
      "train_lgbmr_lr_734.csv\n",
      "train_lgbmr_lr_736.csv\n",
      "train_lgbmr_lr_737.csv\n",
      "train_lgbmr_lr_738.csv\n",
      "train_lgbmr_lr_741.csv\n",
      "train_lgbmr_lr_742.csv\n",
      "train_lgbmr_lr_743.csv\n",
      "train_lgbmr_lr_744.csv\n",
      "train_lgbmr_lr_750.csv\n",
      "train_lgbmr_lr_751.csv\n",
      "train_lgbmr_lr_752.csv\n",
      "train_lgbmr_lr_753.csv\n",
      "train_lgbmr_lr_754.csv\n",
      "train_lgbmr_lr_755.csv\n",
      "train_lgbmr_lr_757.csv\n",
      "train_lgbmr_lr_758.csv\n",
      "train_lgbmr_lr_760.csv\n",
      "train_lgbmr_lr_763.csv\n",
      "train_lgbmr_lr_765.csv\n",
      "train_lgbmr_lr_766.csv\n",
      "train_lgbmr_lr_767.csv\n",
      "train_lgbmr_lr_769.csv\n",
      "train_lgbmr_lr_770.csv\n",
      "train_lgbmr_lr_772.csv\n",
      "train_lgbmr_lr_774.csv\n",
      "train_lgbmr_lr_775.csv\n",
      "train_lgbmr_lr_776.csv\n",
      "train_lgbmr_lr_777.csv\n",
      "train_lgbmr_lr_779.csv\n",
      "train_lgbmr_lr_780.csv\n",
      "train_lgbmr_lr_781.csv\n",
      "train_lgbmr_lr_782.csv\n",
      "train_lgbmr_lr_783.csv\n",
      "train_lgbmr_lr_784.csv\n",
      "train_lgbmr_lr_786.csv\n",
      "train_lgbmr_lr_790.csv\n",
      "train_lgbmr_lr_791.csv\n",
      "train_lgbmr_lr_793.csv\n",
      "train_lgbmr_lr_794.csv\n",
      "train_lgbmr_lr_796.csv\n",
      "train_lgbmr_lr_797.csv\n",
      "train_lgbmr_lr_798.csv\n",
      "train_lgbmr_lr_799.csv\n",
      "train_lgbmr_lr_data_560508.csv\n",
      "train_lgbmr_lr_data_560514.csv\n",
      "train_lgbmr_lr_data_560542.csv\n",
      "train_lgbmr_lr_data_560543.csv\n",
      "train_lgbmr_lr_data_560545.csv\n",
      "train_lgbmr_lr_data_560552.csv\n",
      "train_lgbmr_lr_data_560554.csv\n",
      "train_lgbmr_lr_data_560560.csv\n",
      "train_lgbmr_lr_data_560564.csv\n",
      "train_lstm_len_10.csv\n",
      "train_ridge_1.csv\n",
      "train_ridge_2.csv\n",
      "train_ridge_3.csv\n",
      "train_ridge_4.csv\n",
      "train_ridge_doufu.csv\n",
      "xgboost_bagging_train_0.6144701277264_03071445.csv\n",
      "xgboost_bagging_train_0.6200702774032506_03071107.csv\n"
     ]
    }
   ],
   "source": [
    "for (root, dirs, files) in os.walk(\"../models/__models__/\"):\n",
    "    for filename in files:\n",
    "        if 'train' in filename:\n",
    "            print(filename)\n",
    "            trainfile = os.path.join(root,filename)\n",
    "            data_stacking = pd.merge(data_stacking, merge(trainfile), on = 'Id', how = 'left')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "done...\n"
     ]
    }
   ],
   "source": [
    "data_stacking.to_csv('../input/data_stacking.csv', index = False)\n",
    "print('done...')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 130000 entries, 0 to 129999\n",
      "Columns: 261 entries, Id to Score_xgb_bagging_y\n",
      "dtypes: float64(259), int64(1), object(1)\n",
      "memory usage: 259.9+ MB\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "print(data_stacking.info())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
